package com.schoolvisitors.controller.user;

import com.schoolvisitors.context.UserContext;
import com.schoolvisitors.entity.User;
import com.schoolvisitors.response.ResultBody;
import com.schoolvisitors.service.UserService;
import com.schoolvisitors.vo.UserVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/getUserInfo")
    public ResultBody getUserInfo() {
        User user = UserContext.getUser();
        user = userService.findById(user.getId());

        UserVo userVo = new UserVo();
        userVo.setRealName(user.getRealName());
        userVo.setPoints(user.getPoints());
        return ResultBody.success(userVo);
    }
}
